package com.tfswx.jcyw.print.config;


import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * 公共配置
 *
 * @author 张述江
 * @date 2022/3/1
 */
public abstract class Ggpz {

    /**
     * APPID
     */
    //    public static final String APP_ID = "f9d8e3259d2c57e06f57e4f85f1d0809854d73f7dc1c914eccbe7bd427af0244da45f34d7fb85056e9fa36b0ad464d45";
    public static final File BASE_DIR;
    public static final File LOG_DIR;
    public static final File AZB_DIR;

    static {
        String basePath = System.getProperty("basePath");
        if (StringUtils.isBlank(basePath)) {
            String userHome = System.getProperty("user.home");
            basePath = new File(userHome, ".config").getAbsolutePath();
        }
        try {
            basePath = new File(basePath, "print-client").getCanonicalPath();
        } catch (Exception e) {
            System.err.println("basePath存在问题，请检查！");
            System.exit(1);
        }
        createDir((BASE_DIR = new File(basePath)));
        createDir((LOG_DIR = new File(BASE_DIR, "logs")));
        createDir((AZB_DIR = new File(BASE_DIR, "azb")));
    }

    private static void createDir(@NonNull File file) {
        if (!file.exists() && !file.mkdirs()) {
            throw new RuntimeException(file.getName() + " 目录创建失败");
        }
    }
}
